package com.ycsj.goldmedalnewconcept.student.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ycsj.common.base.BaseApplication;
import com.ycsj.common.image.ImageUtil;
import com.ycsj.common.utils.ScreenUtils;
import com.ycsj.common.utils.UiUtils;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.student.bean.DjInfo;

import java.util.List;

/**
 * 动态
 * Created by Administrator on 2019/3/1 0001.
 */

public class DtRvAdapter extends BaseQuickAdapter<DjInfo.DataBean, BaseViewHolder> {

    private OnClickUseDjListener onClickUseDjListener;

    private LinearLayout.LayoutParams lp;

    public DtRvAdapter(Context context, int layoutResId, @Nullable List<DjInfo.DataBean> data) {
        super(layoutResId, data);
        lp = new LinearLayout.LayoutParams((ScreenUtils.getScreenWidth(context) - UiUtils.dp2px(36)) / 2, ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    @Override
    protected void convert(BaseViewHolder helper, final DjInfo.DataBean item) {

        //最外层的布局
        RelativeLayout rlOut = helper.getView(R.id.rl_out);
        rlOut.setLayoutParams(lp);

        //显示数量的TextView
        TextView tvNum = helper.getView(R.id.tv_num);
        tvNum.setText(item.getAmount() + "/" + item.getMax_amount());

        //学习卡类型
        TextView tv_card_name = helper.getView(R.id.tv_card_name);
        tv_card_name.setText(item.getType());

        //学习卡图片
        ImageView lvCard = helper.getView(R.id.lv_card);
        ImageUtil.displayImage(BaseApplication.context, lvCard, item.getImg_tool(), R.drawable.book);

        //卡片功能描述的TextView
        TextView tv_jyz = helper.getView(R.id.tv_jyz);
        tv_jyz.setText(item.getMsg());

        //使用道具
        Button btUse = helper.getView(R.id.bt_use);
        btUse.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //使用道具的点击事件
                if (null != onClickUseDjListener) {
                    onClickUseDjListener.onUseDj(item);
                }
            }
        });

    }

    public void setOnClickUseDjListener(OnClickUseDjListener onClickUseDjListener) {
        this.onClickUseDjListener = onClickUseDjListener;
    }

    /**
     * 使用道具的回调接口
     */
    public interface OnClickUseDjListener {
        void onUseDj(DjInfo.DataBean item);
    }


}
